﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.Persistent;
using System.Data;
using Jumpton.Data;
using Jumpton.SFA.Server.Entity;

namespace Jumpton.SFA.Server.BusinessRule.InStoreDataMeasures
{
    public class MeasuresGroupItemManager : BusinessLogic
    {
        public MEASURE_ITEMS Load(int ID)
        {
            return (MEASURE_ITEMS)ObjectRow.Load(typeof(MEASURE_ITEMS), string.Format("this.ID={0}", ID));
        }

        //绑定判断是否有效
        public ObjectTable GetActiveYes(int Valid, decimal domainid)
        {
            StringBuilder sb = new StringBuilder();
            if (Valid >= 0)
            {
                sb.AppendFormat("this.ACTIVE='{0}'", Valid);
            }
            if (domainid > 0)
            {
                sb.AppendFormat("and this.DOMAINID='{0}'", domainid);
            }
            return new ObjectTable(typeof(MEASURE_ITEMS), sb.ToString().TrimStart('a', 'n', 'd'));
        }

        public ObjectTable GetMeasuresGroupItemTable(decimal domainid, string itemid,string where)
        {
           
            if (!string.IsNullOrEmpty(itemid))
                where += " AND MEASUER_GROUP_ID='" + itemid + "'";
            return new ObjectTable(typeof(MEASURE_ITEMS), "this.DOMAINID='" + domainid + "' " + where);
            
        }

        public MEASURE_ITEMS Load(decimal domainID, string code)
        {
            return (MEASURE_ITEMS)ObjectRow.Load(typeof(MEASURE_ITEMS), string.Format("this.DOMAINID='{0}' and this.CODE='{1}'", domainID, code));
        }




        public bool Save(MEASURE_ITEMS measuregroup)
        {
            try
            {
                
                if (measuregroup.State == DataRowState.Added)
                {
                    measuregroup.CREATETIME = long.Parse(BusinessLogic.GetDateTimeString(DateTime.Now));
                }
                measuregroup.Save();

                return true;
            }
            catch (Exception ex)
            {
                measuregroup.Connection.RollbackTransaction();
                this.message = ex.Message;
                throw ex;
            }
        }

        public ObjectTable GetMeasureGroupItemList(string domainID, string updatetime)
        {
            return new ObjectTable(typeof(MEASURE_ITEMS), "this.DOMAINID=" + domainID + " and this.LAST_UPDATE_TIME>'" + updatetime + "'");
        }

        public DataSet GetMeasuresItemTable(string domainID, string user_id, string updatetime)
        {
            string strSql = "";

            DataSet ds = SqlData.OpenSql(strSql);
            return ds;
        }

       



    }
}
